package com.yanqu.road.dao.impl.activity.dragonboatrace;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.dragonboatrace.config.DragonBoatRacePlaceConfig;
import com.yanqu.road.entity.activity.dragonboatrace.config.DragonBoatRaceSpeedConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 * @Author cwq
 * @Data 2021/5/18 16:00
 */
public class DragonBoatRaceConfigDaoImpl extends TempDao {

    private static String getDragonBoatRacePlaceConfigSql = "select * from `t_s_activity_boat_place` where `activityId`=? ORDER BY `id` ASC";
    public List<DragonBoatRacePlaceConfig> getDragonBoatRacePlaceConfigList(int id) {
        List<DragonBoatRacePlaceConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getDragonBoatRacePlaceConfigSql);
            int i = 1;
            call.setInt(i++, id);
            rs = call.executeQuery();
            while (rs.next()) {
                DragonBoatRacePlaceConfig dragonBoatRacePlaceConfig = new DragonBoatRacePlaceConfig();
                dragonBoatRacePlaceConfig.setActivityId(rs.getInt("activityId"));
                dragonBoatRacePlaceConfig.setId(rs.getInt("id"));
                dragonBoatRacePlaceConfig.setName(rs.getString("name"));
                dragonBoatRacePlaceConfig.setDesc(rs.getString("desc"));
                dragonBoatRacePlaceConfig.setIcon(rs.getString("icon"));
                dragonBoatRacePlaceConfig.setPlaceCoordinate(rs.getString("placeCoordinate"));
                dragonBoatRacePlaceConfig.setDistance(rs.getInt("distance"));
                dragonBoatRacePlaceConfig.setRewards(rs.getString("rewards"));
                list.add(dragonBoatRacePlaceConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getDragonBoatRaceSpeedConfigSql = "select * from `t_s_activity_boat_speed` where `activityId`=? ORDER BY `id` ASC";
    public List<DragonBoatRaceSpeedConfig> getDragonBoatRaceSpeedConfigList(int id) {
        List<DragonBoatRaceSpeedConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getDragonBoatRaceSpeedConfigSql);
            int i = 1;
            call.setInt(i++, id);
            rs = call.executeQuery();
            while (rs.next()) {
                DragonBoatRaceSpeedConfig dragonBoatRaceSpeedConfig = new DragonBoatRaceSpeedConfig();
                dragonBoatRaceSpeedConfig.setActivityId(rs.getInt("activityId"));
                dragonBoatRaceSpeedConfig.setId(rs.getInt("id"));
                dragonBoatRaceSpeedConfig.setName(rs.getString("name"));
                dragonBoatRaceSpeedConfig.setEffect(rs.getInt("effect"));
                dragonBoatRaceSpeedConfig.setExtraSpeed(rs.getInt("extraSpeed"));
                dragonBoatRaceSpeedConfig.setPixel(rs.getInt("pixel"));
                list.add(dragonBoatRaceSpeedConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

}
